package com.gosling.cloudspace.tools;

import com.google.common.base.Strings;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.security.SecureRandom;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author lihonglin
 * @date 2022/5/27 10:56
 */
@SuppressWarnings({"unused", "rawtypes", "unchecked"})
public class StringTool {
    public static final byte[] BOM = {-17, -69, -65};
    public static final char[] HexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
    public static final String CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    public static final Pattern PTitle = Pattern.compile("<title>(.+?)</title>", 34);
    public static final Pattern PLetterOrDigit = Pattern.compile("^\\w*$", 34);
    public static final Pattern PLetter = Pattern.compile("^[A-Za-z]*$", 34);
    public static final Pattern PDigit = Pattern.compile("^\\d*$", 34);
    /**
     * 汉语中数字大写
     */
    private static final String[] CN_UPPER_NUMBER = {"零", "壹", "贰", "叁", "肆",
            "伍", "陆", "柒", "捌", "玖"};
    /**
     * 汉语中货币单位大写，这样的设计类似于占位符
     */
    private static final String[] CN_UPPER_MONETRAY_UNIT = {"分", "角", "元",
            "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆", "拾",
            "佰", "仟"};
    /**
     * 特殊字符：整
     */
    private static final String CN_FULL = "整";
    /**
     * 特殊字符：负
     */
    private static final String CN_NEGATIVE = "负";
    /**
     * 金额的精度，默认值为2
     */
    private static final int MONEY_PRECISION = 2;
    /**
     * 特殊字符：零元整
     */
    private static final String CN_ZEOR_FULL = "零元" + CN_FULL;
    public static Pattern patternHtmlTag = Pattern.compile("<[^<>]+>", 32);
    public static int charset_default = 0;
    public static int charset_ISO_GBK = 1;
    public static int charset_GBK_ISO = 2;
    private static Logger LOGGER = LoggerFactory.getLogger(StringTool.class);
    private static Pattern chinesePattern = Pattern.compile("[^一-龥]+", 34);
    private static Pattern idPattern = Pattern.compile("[\\w\\s\\_\\.\\,]*", 34);

    public static String byteToBin(byte[] bs) {
        char[] cs = new char[bs.length * 9];
        for (int i = 0; i < bs.length; ++i) {
            byte b = bs[i];
            int j = i * 9;
            cs[j] = (((b >>> 7 & 0x1) == 1) ? 49 : '0');
            cs[(j + 1)] = (((b >>> 6 & 0x1) == 1) ? 49 : '0');
            cs[(j + 2)] = (((b >>> 5 & 0x1) == 1) ? 49 : '0');
            cs[(j + 3)] = (((b >>> 4 & 0x1) == 1) ? 49 : '0');
            cs[(j + 4)] = (((b >>> 3 & 0x1) == 1) ? 49 : '0');
            cs[(j + 5)] = (((b >>> 2 & 0x1) == 1) ? 49 : '0');
            cs[(j + 6)] = (((b >>> 1 & 0x1) == 1) ? 49 : '0');
            cs[(j + 7)] = (((b & 0x1) == 1) ? 49 : '0');
            cs[(j + 8)] = ',';
        }
        return new String(cs);
    }

    public static String byteArrayToHexString(byte[] b) {
        StringBuffer resultSb = new StringBuffer();
        for (int i = 0; i < b.length; ++i) {
            resultSb.append(byteToHexString(b[i]));
            resultSb.append(" ");
        }
        return resultSb.toString();
    }

    private static String byteToHexString(byte b) {
        int n = b;
        if (n < 0)
            n = 256 + n;
        int d1 = n / 16;
        int d2 = n % 16;
        return new StringBuilder().append(HexDigits[d1]).append("").append(HexDigits[d2]).toString();
    }

    public static String javaEncode(String txt) {
        if ((txt == null) || (txt.length() == 0)) {
            return txt;
        }
        txt = replaceEx(txt, "\\", "\\\\");
        txt = replaceEx(txt, "\r\n", "\n");
        txt = replaceEx(txt, "\r", "\\r");
        txt = replaceEx(txt, "\t", "\\t");
        txt = replaceEx(txt, "\n", "\\n");
        txt = replaceEx(txt, "\"", "\\\"");
        txt = replaceEx(txt, "'", "\\'");
        return txt;
    }

    public static String[] splitEx(String str, String spilter) {
        if (str == null)
            return null;
        if ((spilter == null) || (spilter.equals("")) || (str.length() < spilter.length())) {
            String[] t = {str};
            return t;
        }
        ArrayList al = new ArrayList();
        char[] cs = str.toCharArray();
        char[] ss = spilter.toCharArray();
        int length = spilter.length();
        int lastIndex = 0;
        for (int i = 0; i <= str.length() - length; ) {
            boolean notSuit = false;
            for (int j = 0; j < length; ++j) {
                if (cs[(i + j)] != ss[j]) {
                    notSuit = true;
                    break;
                }
            }
            if (!(notSuit)) {
                al.add(str.substring(lastIndex, i));
                i += length;
                lastIndex = i;
            } else {
                ++i;
            }
        }
        if (lastIndex <= str.length()) {
            al.add(str.substring(lastIndex, str.length()));
        }
        String[] t = new String[al.size()];
        for (int i = 0; i < al.size(); ++i) {
            t[i] = ((String) al.get(i));
        }
        return t;
    }

    public static String replaceEx(String str, String subStr, String reStr) {
        if (str == null) {
            return null;
        }
        if ((subStr == null) || (subStr.equals("")) || (subStr.length() > str.length()) || (reStr == null)) {
            return str;
        }
        StringBuffer sb = new StringBuffer();
        int lastIndex = 0;
        while (true) {
            int index = str.indexOf(subStr, lastIndex);
            if (index < 0) {
                break;
            }
            sb.append(str.substring(lastIndex, index));
            sb.append(reStr);
            lastIndex = index + subStr.length();
        }
        sb.append(str.substring(lastIndex));
        return sb.toString();
    }

    public static String replaceAllIgnoreCase(String source, String oldstring, String newstring) {
        Pattern p = Pattern.compile(oldstring, 34);
        Matcher m = p.matcher(source);
        return m.replaceAll(newstring);
    }

    public static String quotEncode(String txt) {
        if ((txt == null) || (txt.length() == 0))
            return txt;
        txt = replaceEx(txt, "&", "&amp;");
        txt = replaceEx(txt, "\"", "&quot;");
        return txt;
    }

    public static String quotDecode(String txt) {
        if ((txt == null) || (txt.length() == 0))
            return txt;
        txt = replaceEx(txt, "&quot;", "\"");
        txt = replaceEx(txt, "&amp;", "&");
        return txt;
    }

    public static String escape(String src) {
        StringBuffer sb = new StringBuffer();
        sb.ensureCapacity(src.length() * 6);
        for (int i = 0; i < src.length(); ++i) {
            char j = src.charAt(i);
            if ((Character.isDigit(j)) || (Character.isLowerCase(j)) || (Character.isUpperCase(j))) {
                sb.append(j);
            } else if (j < 256) {
                sb.append("%");
                if (j < '\16') {
                    sb.append("0");
                }
                sb.append(Integer.toString(j, 16));
            } else {
                sb.append("%u");
                sb.append(Integer.toString(j, 16));
            }
        }
        return sb.toString();
    }

    public static String leftPad(String srcString, char c, int length) {
        if (srcString == null)
            srcString = "";
        int tLen = srcString.length();
        if (tLen >= length)
            return srcString;
        int iMax = length - tLen;
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < iMax; ++i)
            sb.append(c);
        sb.append(srcString);
        return sb.toString();
    }

    public static String subString(String src, int length) {
        if (src == null)
            return null;
        int i = src.length();
        if (i > length)
            return src.substring(0, length);
        return src;
    }

    public static String subStringEx(String src, int length) {
        length *= 2;
        if (src == null) {
            return null;
        }
        int k = lengthEx(src);
        if (k > length) {
            int m = 0;
            boolean unixFlag = false;
            String osname = System.getProperty("os.name").toLowerCase();
            if ((osname.indexOf("sunos") > 0) || (osname.indexOf("solaris") > 0) || (osname.indexOf("aix") > 0)) {
                unixFlag = true;
            }
            try {
                byte[] b = src.getBytes("Unicode");
                for (int i = 2; i < b.length; i += 2) {
                    byte flag = b[(i + 1)];
                    if (unixFlag) {
                        flag = b[i];
                    }
                    if (flag == 0) {
                        ++m;
                    } else {
                        m += 2;
                    }
                    if (m > length) {
                        return src.substring(0, (i - 2) / 2);
                    }
                }
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                throw new RuntimeException("执行方法getBytes(\"Unicode\")时出错！");
            }
        }
        return src;
    }

    public static int lengthEx(String src) {
        int length = 0;
        boolean unixFlag = false;
        String osname = System.getProperty("os.name").toLowerCase();
        if ((osname.indexOf("sunos") > 0) || (osname.indexOf("solaris") > 0) || (osname.indexOf("aix") > 0)) {
            unixFlag = true;
        }
        try {
            byte[] b = src.getBytes("Unicode");
            for (int i = 2; i < b.length; i += 2) {
                byte flag = b[(i + 1)];
                if (unixFlag)
                    flag = b[i];
                if (flag == 0)
                    ++length;
                else
                    length += 2;
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            throw new RuntimeException("执行方法getBytes(\"Unicode\")时出错！");
        }
        return length;
    }

    public static String rightPad(String srcString, char c, int length) {
        if (srcString == null)
            srcString = "";
        int tLen = srcString.length();
        if (tLen >= length)
            return srcString;
        int iMax = length - tLen;
        StringBuffer sb = new StringBuffer();
        sb.append(srcString);
        for (int i = 0; i < iMax; ++i)
            sb.append(c);
        return sb.toString();
    }

    public static void printStringWithAnyCharset(String str) {
        Map map = Charset.availableCharsets();
        Object[] keys = map.keySet().toArray();
        for (int i = 0; i < keys.length; ++i) {
            for (int j = 0; j < keys.length; ++j) {
                System.out.print("\t");
                try {
                    LOGGER.debug(new StringBuilder().append("From ").append(keys[i]).append(" To ").append(keys[j]).append(":").append(new String(str.getBytes(keys[i].toString()), keys[j].toString())).toString());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static String toDBC(String input) {
        char[] c = input.toCharArray();
        for (int i = 0; i < c.length; ++i)
            if (c[i] == 12288) {
                c[i] = ' ';
            } else if ((c[i] > 65280) && (c[i] < 65375))
                c[i] = (char) (c[i] - 65248);
        return new String(c);
    }

    public static String getHtmlTitle(String html) {
        Matcher m = PTitle.matcher(html);
        if (m.find())
            return m.group(1).trim();
        return null;
    }

    public static boolean isEmpty(String str) {
        if ((str == null) || ("null".equals(str)))
            return true;
        return (str.trim().length() == 0);
    }

    public static boolean isNotEmpty(String str) {
        return (!(isEmpty(str)));
    }

    public static void nullToBlank(String[] params) {
        String[] arr$ = params;
        int len$ = arr$.length;
        for (int i$ = 0; i$ < len$; ++i$) {
            String param = arr$[i$];
            if ((param == null) || ("null".equals(param)))
                param = "";
            param = param.trim();
        }
    }

    public static String noNull(String string, String defaultString) {
        return ((isEmpty(string)) ? defaultString : string);
    }

    public static String noNull(String string) {
        return noNull(string, "");
    }

    public static String join(Object[] arr) {
        return join(arr, ",");
    }

    public static String join(Object[][] arr) {
        return join(arr, "\n", ",");
    }

    public static String join(Object[] arr, String spliter) {
        if (arr == null) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < arr.length; ++i) {
            if (i != 0) {
                sb.append(spliter);
            }
            sb.append(arr[i]);
        }
        return sb.toString();
    }

    public static String join(Object[][] arr, String spliter1, String spliter2) {
        if (arr == null)
            return null;
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < arr.length; ++i) {
            if (i != 0)
                sb.append(spliter2);
            sb.append(join(arr[i], spliter2));
        }
        return sb.toString();
    }

    public static String join(List list) {
        return join(list, ",");
    }

    public static String join(List list, String spliter) {
        if (list == null)
            return null;
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < list.size(); ++i) {
            if (i != 0)
                sb.append(spliter);
            sb.append(list.get(i));
        }
        return sb.toString();
    }

    public static int count(String str, String findStr) {
        int lastIndex = 0;
        int length = findStr.length();
        int count = 0;
        int start = 0;
        while ((start = str.indexOf(findStr, lastIndex)) >= 0) {
            lastIndex = start + length;
            ++count;
        }
        return count;
    }

    public static boolean isLetterOrDigit(String str) {
        return PLetterOrDigit.matcher(str).find();
    }

    public static boolean isLetter(String str) {
        return PLetter.matcher(str).find();
    }

    public static boolean isDigit(String str) {
        if (isEmpty(str))
            return false;
        return PDigit.matcher(str).find();
    }

    public static boolean containsChinese(String str) {
        return (!(chinesePattern.matcher(str).matches()));
    }

    public static boolean checkID(String str) {
        if (isEmpty(str)) {
            return true;
        }
        return (idPattern.matcher(str).matches());
    }

    public static String getURLExtName(String url) {
        if (isEmpty(url))
            return null;
        int index1 = url.indexOf(63);
        if (index1 == -1)
            index1 = url.length();
        int index2 = url.lastIndexOf(46, index1);
        if (index2 == -1)
            return null;
        int index3 = url.indexOf(47, 8);
        if (index3 == -1)
            return null;
        String ext = url.substring(index2 + 1, index1);
        if (ext.matches("[^\\/\\\\]*"))
            return ext;
        return null;
    }

    public static String getURLFileName(String url) {
        if (isEmpty(url))
            return null;
        int index1 = url.indexOf(63);
        if (index1 == -1)
            index1 = url.length();
        int index2 = url.lastIndexOf(47, index1);
        if ((index2 == -1) || (index2 < 8))
            return null;
        String ext = url.substring(index2 + 1, index1);
        return ext;
    }

    public static String firstCharToUpCase(String str) {
        String ret = null;
        if ((str != null) && (str.length() >= 1)) {
            ret = new StringBuilder().append(str.substring(0, 1).toUpperCase()).append(str.substring(1, str.length())).toString();
        }
        return ret;
    }

    public static final String convertCharset(int convertType, String str) {
        try {
            if (convertType == charset_ISO_GBK)
                return new String(str.getBytes("ISO8859_1"), "GB2312");
            if (convertType == charset_GBK_ISO)
                return new String(str.getBytes("GB2312"), "ISO8859_1");
            return str;
        } catch (Exception e) {
        }
        return "";
    }

    public static final String getParamValue(String strQuery, String param) {
        if (strQuery == null)
            return "";
        String value = new String();
        int nIndex = strQuery.indexOf("?");
        if (nIndex != -1)
            strQuery = strQuery.substring(nIndex + 1);
        StringTokenizer token = new StringTokenizer(strQuery, "&", true);
        while (token.hasMoreTokens()) {
            int intPos;
            String tmp = token.nextToken();
            if ((intPos = tmp.indexOf(new StringBuilder().append(param).append("=").toString(), 0)) == 0) {
                value = tmp.substring(intPos + param.length() + 1, tmp.length());
                break;
            }
        }
        return value;
    }

    public static final String[] strSplit(String resource, String keyword) {
        StringTokenizer st = new StringTokenizer(resource, keyword);
        String[] strs = new String[st.countTokens()];
        int i = 0;
        while (st.hasMoreElements()) {
            strs[i] = ((String) st.nextElement());
            i += 1;
        }
        return strs;
    }

    public static final String transNumToStr(int num, int len) {
        String result = "";
        String str = Integer.toString(num);
        int a = len - str.length();
        if (a > 0) {
            for (int i = a; i >= 1; --i)
                result = new StringBuilder().append(result).append("0").toString();
        }
        result = new StringBuilder().append(result).append(str).toString();
        return result;
    }

    public static final String spaceToNull(String str) {
        if ((!(str.equals(""))) && (!(str.equals(" "))))
            throw new IllegalArgumentException();
        return null;
    }

    public static final String trimString(String str) {
        if (str == null)
            return "";
        char[] chArr = str.toCharArray();
        int l = chArr.length;
        int length = l;
        while ((l > 0) && (chArr[(l - 1)] <= ' '))
            --l;
        if (l == 0)
            return "";
        return ((l < length) ? str.substring(0, l) : str);
    }

    public static final String getStrBeforeSeparator(String str, String separator) {
        if ((separator.length() == 0) || (str.length() == 0))
            throw new IllegalArgumentException();
        int i = str.indexOf(separator);
        if (i == -1)
            return str;
        return str.substring(0, i);
    }

    public static final String getStrAfterSeparator(String str, String separator) {
        if ((separator.length() == 0) || (str.length() == 0))
            throw new IllegalArgumentException();
        int i = str.indexOf(separator);
        if (i == -1)
            return null;
        return str.substring(i + separator.length());
    }

    public static final String[] gbToUnicode(String[] srcAry) {
        int l = srcAry.length;
        for (int i = 0; i < l; ++i)
            srcAry[i] = gbToUnicode(srcAry[i]);
        return srcAry;
    }

    public static final String gbToUnicode(String str) {
        char[] c = str.toCharArray();
        int n = c.length;
        byte[] b = new byte[n];
        for (int i = 0; i < n; ++i)
            b[i] = (byte) c[i];
        return new String(b);
    }

    public static final String[] unicodeToGb(String[] srcAry) {
        int l = srcAry.length;
        for (int i = 0; i < l; ++i)
            srcAry[i] = unicodeToGb(srcAry[i]);
        return srcAry;
    }

    public static final String unicodeToGb(String src) {
        byte[] b = src.getBytes();
        int n = b.length;
        char[] c = new char[n];
        for (int i = 0; i < n; ++i)
            c[i] = (char) ((short) b[i] & 0xFF);
        return new String(c);
    }

    public static final String getStrBetween(String source, String strBegin, String strEnd) {
        if ((strBegin.equals(strEnd)) || (strBegin.indexOf(strEnd) != -1) || (strEnd.indexOf(strBegin) != -1) || (strBegin.length() == 0) || (source.length() == 0) || (strEnd.length() == 0)) {
            throw new IllegalArgumentException();
        }
        int begin = source.indexOf(strBegin);
        int end = source.indexOf(strEnd);
        if ((begin == -1) || (end == -1))
            return null;
        begin += strBegin.length();
        return source.substring(begin, end);
    }

    public static String randomString() {
        Random random = new Random();
        String s = "";
        for (int i = 0; i < 6 + random.nextInt(5); ++i) {
            s = new StringBuilder().append(s).append("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ#$%^@".charAt(random.nextInt("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ#$%^@".length()))).toString();
        }
        return s;
    }

    public static int getStringTrueLength(String s) {
        if (s == null)
            return 0;
        byte[] abyte0 = s.getBytes();
        if (abyte0 == null)
            return 0;
        return abyte0.length;
    }

    public static boolean isNotNullOrBlank(Object s) {
        return (!(isNullOrBlank(s)));
    }

    public static boolean isNullOrBlank(Object s) {
        boolean flag = false;
        if (s == null)
            flag = true;
        else if (String.valueOf(s).trim().length() == 0)
            flag = true;
        return flag;
    }

    public static Object nullValueConvery(Object obj) {
        Object ret;
        if (obj == null)
            ret = "";
        else
            ret = obj;
        return ret;
    }

    public static boolean isEmail(String s) {
        return (!(isNullOrBlank(s)));
    }

    public static boolean isPhone(String s) {
        return (!(isNullOrBlank(s)));
    }

    public static boolean isMobile(String s) {
        return (!(isNullOrBlank(s)));
    }

    public static boolean isNumericStr(String str) {
        boolean ret = true;
        if ((str == null) || (str.length() == 0)) {
            ret = false;
        } else {
            char[] cArray = str.toCharArray();
            for (int i = 0; i < cArray.length; ++i) {
                char c = cArray[i];
                if ((c >= '0') && (c <= '9'))
                    break;
                ret = false;
            }
        }
        return ret;
    }

    public static boolean isNumericOrLetterStr(String str) {
        boolean ret = true;
        if ((str == null) || (str.length() == 0)) {
            ret = false;
        } else {
            char[] cArray = str.toCharArray();
            for (int i = 0; i < cArray.length; ++i) {
                char c = cArray[i];
                if ((((c < '0') || (c > '9'))) && (((c < 'a') || (c > 'z')))) {
                    if ((c >= 'A') && (c <= 'Z'))
                        break;
                    ret = false;
                }
            }
        }
        return ret;
    }

    public static String getPhoneCode(String areaNumber, String phoneNumber, String split) {
        StringBuffer ret = new StringBuffer();
        String number = "";
        if (isNullOrBlank(split)) {
            split = "-";
        }
        number = areaNumber;
        if (!(isNullOrBlank(number))) {
            number = trimString(number);
            if (isNumericStr(number)) {
                ret.append(number);
                ret.append(split);
            }
        }
        number = phoneNumber;
        if (!(isNullOrBlank(number))) {
            number = trimString(number);
            if (isNumericStr(number))
                ret.append(number);
        }
        return ret.toString();
    }

    public static String getSubString(String sourse, int count) {
        String ret = null;
        if (sourse != null) {
            if (sourse.length() > count)
                ret = new StringBuilder().append(sourse.substring(0, count)).append("..").toString();
            else
                ret = sourse;
        }
        return ret;
    }

    public static String[] getAreaNumberPhoneNumber(String phoneCode, String split) {
        String[] ret = new String[2];
        if (isNullOrBlank(split))
            split = "-";
        if (isNullOrBlank(phoneCode)) {
            ret[0] = "";
            ret[1] = "";
            return ret;
        }
        String[] temps = phoneCode.split(split);
        if (temps != null) {
            if (temps.length == 2) {
                String temp = null;
                temp = temps[0];
                temps[0] = temps[1];
                temps[1] = temp;
                ret = temps;
            } else if (temps.length == 1) {
                ret[0] = temps[0];
                ret[1] = "";
            }
        }
        return ret;
    }

    public static String generateRandomString(int length, String chars) {
        if (isNullOrBlank(chars))
            chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        StringBuilder sb = new StringBuilder(length);
        SecureRandom random = new SecureRandom();
        for (int i = 0; i < length; ++i)
            sb.append(chars.charAt(random.nextInt(chars.length())));
        return sb.toString();
    }

    public static void removeItemForList(List<String> list, String item) {
        if (list == null) {
            return;
        }
        Iterator it = list.iterator();
        while (true) {
            do {
                if (!(it.hasNext())) {
                    return;
                }
            }
            while (!(((String) it.next()).equals(item)));
            it.remove();
        }
    }

    public static List<String> convertArrayToList(String[] array) {
        List list = new ArrayList();
        String[] arr$ = array;
        int len$ = arr$.length;
        for (int i$ = 0; i$ < len$; ++i$) {
            String str = arr$[i$];
            list.add(str);
        }
        return list;
    }

    public static String generateVerifyCode(int c) {
        StringBuilder verifyCode = new StringBuilder();
        int[] chars = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
        for (int i = 0; i < c; ++i) {
            verifyCode.append(chars[new Random().nextInt(10)]);
        }
        return verifyCode.toString();
    }

    public static String getSMSTemplate1(String verifyCode) {
        return new StringBuilder().append("您的验证码：[").append(verifyCode).append("]，").append("1分钟内有效【北京郁金香投资基金管理有限公司】").toString();
    }

    public static boolean isEmptyForInteger(Integer param) {
        return ((param != null) && (param.intValue() >= 0));
    }

    public static boolean isEmptyForDouble(Double param) {
        return ((param != null) && (param.doubleValue() >= 0D));
    }

    public static List<String> split(String str, String d) {
        List l = new ArrayList();
        if (isNotEmpty(str)) {
            String[] ar = str.split(d);
            String[] arr$ = ar;
            int len$ = arr$.length;
            for (int i$ = 0; i$ < len$; ++i$) {
                String a = arr$[i$];
                l.add(a);
            }
        }
        return l;
    }

    public static String joinstr(List<String> str, String d) {
        String st = "";
        for (Iterator i$ = str.iterator(); i$.hasNext(); ) {
            String s = (String) i$.next();
            if ("".equals(st))
                st = s;
            else
                st = new StringBuilder().append(st).append(d).append(s).toString();
        }
        return st;
    }

    public static Map<String, String> convertBean(Object bean) throws IntrospectionException, IllegalAccessException, InvocationTargetException {
        Class type = bean.getClass();
        Map returnMap = new HashMap(16);
        BeanInfo beanInfo = Introspector.getBeanInfo(type);
        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
        for (int i = 0; i < propertyDescriptors.length; ++i) {
            PropertyDescriptor descriptor = propertyDescriptors[i];
            String propertyName = descriptor.getName();
            if (!(propertyName.equals("class"))) {
                Method readMethod = descriptor.getReadMethod();
                Object result = readMethod.invoke(bean, new Object[0]);
                if (result != null)
                    returnMap.put(propertyName, String.valueOf(result));
                else
                    returnMap.put(propertyName, "");
            }
        }
        return returnMap;
    }

    public static Object convertMap(Class type, Map<String, String> map) throws IntrospectionException, IllegalAccessException, InstantiationException, InvocationTargetException {
        BeanInfo beanInfo = Introspector.getBeanInfo(type);
        Object obj = type.newInstance();
        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
        for (int i = 0; i < propertyDescriptors.length; ++i) {
            PropertyDescriptor descriptor = propertyDescriptors[i];
            String propertyName = descriptor.getName();
            if (map.containsKey(propertyName)) {
                Object value = map.get(propertyName);
                Object[] args = new Object[1];
                args[0] = value;
                descriptor.getWriteMethod().invoke(obj, args);
            }
        }
        return obj;
    }

    public static String camel2Underline(String param) {
        Pattern p = Pattern.compile("[A-Z]");
        if ((param == null) || (param.equals("")))
            return "";
        StringBuilder builder = new StringBuilder(param);
        Matcher mc = p.matcher(param);
        int i = 0;
        while (mc.find()) {
            builder.replace(mc.start() + i, mc.end() + i, new StringBuilder().append("_").append(mc.group().toLowerCase()).toString());
            ++i;
        }
        if ('_' == builder.charAt(0))
            builder.deleteCharAt(0);
        return builder.toString();
    }

    public static boolean blank(String input) {
        return ((input == null) || ("".equals(input)) || (input.length() == 0) || (input.trim().length() == 0));
    }

    public static boolean notBlank(String input) {
        return (!(blank(input)));
    }

    public static int indexOf(String orig, String sub, int len, int i) {
        if (orig == null)
            return -1;
        int idx = orig.indexOf(sub, i);
        if (idx == -1)
            return idx;
        if (idx % len == 0)
            return idx;
        i = (idx / len + 1) * len;
        int tmp = -1;
        if ((tmp = indexOf(orig, sub, len, i)) > -1)
            return tmp;
        return -1;
    }

    public static int indexOf(String orig, String sub, int len) {
        return indexOf(orig, sub, len, 0);
    }

    public static int indexOf(String orig, String sub) {
        return indexOf(orig, sub, sub.length(), 0);
    }

    public static String substr(String orig, int length) {
        if (orig == null)
            return "";
        if (orig.length() <= length)
            return orig;
        return new StringBuilder().append(orig.substring(0, length - 1)).append("...").toString();
    }

    public static String toFirstUpperCase(String input) {
        return ((blank(input)) ? input : new StringBuilder().append(input.substring(0, 1).toUpperCase()).append(input.substring(1)).toString());
    }

    public static String fillCharacter(String orig, int num, String fillCharacter, boolean location) {
        if (orig == null)
            return null;
        if (orig.length() >= num)
            return orig;
        StringBuffer sb = new StringBuffer("");
        int i = 0;
        while (true) {
            if (orig.length() + i * fillCharacter.length() >= num)
                break;
            sb.append(fillCharacter);
            ++i;
        }
        if (location)
            orig = new StringBuilder().append(orig).append(sb.substring(0, num - orig.length())).toString();
        else
            orig = new StringBuilder().append(sb.substring(0, num - orig.length())).append(orig).toString();
        return orig;
    }

    public static Object convert(String orig, Class<?> clazz) {
        if (orig == null) return null;
        if (clazz == String.class) return orig;
        if (clazz == Short.TYPE) return Short.valueOf(Short.parseShort(orig));
        if (clazz == Short.class) return new Short(orig);
        if (clazz == Integer.TYPE) return Integer.valueOf(Integer.parseInt(orig));
        if (clazz == Integer.class) return new Integer(orig);
        if (clazz == Long.TYPE) return Long.valueOf(Long.parseLong(orig));
        if (clazz == Long.class) return new Long(orig);
        if (clazz == Float.TYPE) return Float.valueOf(Float.parseFloat(orig));
        if (clazz == Float.class) return new Float(orig);
        if (clazz == Double.TYPE) return Double.valueOf(Double.parseDouble(orig));
        if (clazz == Double.class) return new Double(orig);
        if ((orig.equalsIgnoreCase("t")) || (orig.equalsIgnoreCase("ture")) || (orig.equalsIgnoreCase("y")) || (orig.equalsIgnoreCase("yes"))) {
            if (clazz == Boolean.TYPE) return Boolean.valueOf(true);
            if (clazz != Boolean.class) return new Boolean(true);
        }
        if (clazz == Boolean.TYPE) return Boolean.valueOf(false);
        if (clazz == Boolean.class) return new Boolean(false);
        try {
            if (clazz == Date.class) {
                DateFormat fmt = null;
                if (orig.matches("\\d{14}"))
                    fmt = new SimpleDateFormat("yyyyMMddHHmmss");
                else if (orig.matches("\\d{4}-\\d{1,2}-\\d{1,2} \\d{1,2}:\\d{1,2}:\\d{1,2}"))
                    fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                else if (orig.matches("\\d{1,2}/\\d{1,2}/\\d{4} \\d{1,2}:\\d{1,2}:\\d{1,2}"))
                    fmt = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
                else if (orig.matches("\\d{4}年\\d{1,2}月\\d{1,2}日 \\d{1,2}时\\d{1,2}分\\d{1,2}秒"))
                    fmt = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
                else if (orig.matches("\\d{8}"))
                    fmt = new SimpleDateFormat("yyyyMMdd");
                else if (orig.matches("\\d{4}-\\d{1,2}-\\d{1,2}"))
                    fmt = new SimpleDateFormat("yyyy-MM-dd");
                else if (orig.matches("\\d{1,2}/\\d{1,2}/\\d{4}"))
                    fmt = new SimpleDateFormat("MM/dd/yyyy");
                else if (orig.matches("\\d{4}年\\d{1,2}月\\d{1,2}日"))
                    fmt = new SimpleDateFormat("yyyy年MM月dd日");
                return fmt.parse(orig);
            }
            if (clazz == Calendar.class) {
                Calendar cal = Calendar.getInstance();
                DateFormat fmt = null;
                if (orig.matches("\\d{14}"))
                    fmt = new SimpleDateFormat("yyyyMMddHHmmss");
                else if (orig.matches("\\d{4}-\\d{1,2}-\\d{1,2} \\d{1,2}:\\d{1,2}:\\d{1,2}"))
                    fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                else if (orig.matches("\\d{1,2}/\\d{1,2}/\\d{4} \\d{1,2}:\\d{1,2}:\\d{1,2}"))
                    fmt = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
                else if (orig.matches("\\d{4}年\\d{1,2}月\\d{1,2}日 \\d{1,2}时\\d{1,2}分\\d{1,2}秒"))
                    fmt = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
                else if (orig.matches("\\d{8}"))
                    fmt = new SimpleDateFormat("yyyyMMdd");
                else if (orig.matches("\\d{4}-\\d{1,2}-\\d{1,2}"))
                    fmt = new SimpleDateFormat("yyyy-MM-dd");
                else if (orig.matches("\\d{1,2}/\\d{1,2}/\\d{4}"))
                    fmt = new SimpleDateFormat("MM/dd/yyyy");
                else if (orig.matches("\\d{4}年\\d{1,2}月\\d{1,2}日"))
                    fmt = new SimpleDateFormat("yyyy年MM月dd日");
                cal.setTime(fmt.parse(orig));
                return cal;
            }
        } catch (ParseException e) {
            throw new IllegalArgumentException(new StringBuilder().append("字符串不能转换为").append(clazz.getName()).append("类型.").toString());
        }
        throw new IllegalArgumentException(new StringBuilder().append("字符串不能转换为").append(clazz.getName()).append("类型.").toString());
    }

    public static String convert(Object orig) {
        if (orig == null)
            return null;
        if (orig instanceof String)
            return ((String) orig);
        if (orig instanceof Short)
            return Short.toString(((Short) orig).shortValue());
        if (orig instanceof Integer)
            return Integer.toString(((Integer) orig).intValue());
        if (orig instanceof Long)
            return Long.toString(((Long) orig).longValue());
        if (orig instanceof Float)
            return Float.toString(((Float) orig).floatValue());
        if (orig instanceof Double)
            return Double.toString(((Double) orig).doubleValue());
        if (orig instanceof BigDecimal) {
            BigDecimal bg = new BigDecimal(((BigDecimal) orig).doubleValue());
            return bg.toString();
        }
        if (orig instanceof Boolean)
            return Boolean.toString(((Boolean) orig).booleanValue());
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        if (orig instanceof Date)
            return format.format((Date) orig);
        if (orig instanceof Date)
            return format.format((Date) orig);
        if (orig instanceof Calendar)
            return format.format(((Calendar) orig).getTime());
        throw new IllegalArgumentException("参数类型不支持.");
    }

    public static String[] getValueFromString(String orig, String param, String split) {
        String[] result = new String[0];
        if (StringUtils.isBlank(orig)) {
            return result;
        }
        List list = new ArrayList();
        int len = orig.split(split).length;
        for (int i$ = 0; i$ < len; ++i$) {
            String tmp = orig.split(split)[i$];
            String key = StringUtils.substringBefore(tmp, "=");
            String value = StringUtils.substringAfter(tmp, "=");
            if (param.equals(key)) {
                list.add(value);
            }
        }
        return ((String[]) list.toArray(result));
    }

    public static String null2String(String s) {
        return ((s == null) ? "" : s);
    }

    public static String null2String(String s, String s1) {
        return ((s == null) ? s1 : s);
    }

    public static String methodToClass(Method method) {
        String methodName = method.getName();
        String className = method.getDeclaringClass().getName();
        Class[] typeNames = method.getParameterTypes();
        StringBuilder buffer = new StringBuilder();
        int len$ = typeNames.length;
        for (int i$ = 0; i$ < len$; ++i$) {
            Class type = typeNames[i$];
            buffer.append(type.getName()).append(",");
        }
        buffer.deleteCharAt(buffer.length() - 1);
        return new StringBuilder().append(className).append(".").append(methodName).append("(").append(buffer.toString()).append(")").toString();
    }

    public static String getEndDate(String startDate, String type, int interval) {
        if ((isEmpty(startDate)) || (isEmpty(type))) {
            return null;
        }
        Calendar c1 = Calendar.getInstance(Locale.CHINA);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date d1 = format.parse(startDate);
            c1.setTime(d1);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if ("1".equals(type)) {
            c1.add(5, interval);
        } else if ("2".equals(type)) {
            c1.add(2, interval);
        } else if ("3".equals(type)) {
            c1.set(5, 1);
            c1.add(2, interval);
            c1.add(5, -1);
        }
        return format.format(c1.getTime());
    }

    public static String cnToNumber(String normal) {
        Map map = new HashMap(16);
        map.put("一", Integer.valueOf(1));
        map.put("二", Integer.valueOf(2));
        map.put("三", Integer.valueOf(3));
        map.put("四", Integer.valueOf(4));
        map.put("五", Integer.valueOf(5));
        map.put("六", Integer.valueOf(6));
        map.put("七", Integer.valueOf(7));
        map.put("八", Integer.valueOf(8));
        map.put("九", Integer.valueOf(9));
        map.put("十", Integer.valueOf(10));
        char[] charArray = normal.toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < charArray.length; ++i) {
            char t = normal.charAt(i);
            if (map.containsKey(String.valueOf(t))) {
                sb.append(map.get(String.valueOf(t)));
            } else {
                sb.append(String.valueOf(t));
            }
        }
        return sb.toString();
    }

    public static String replaceJsTag(String str) {
        str = str.replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\\(", "（").replaceAll("\\)", "）").replaceAll("eval\\((.*)\\)", "").replaceAll("[\\\"\\'][\\s]*javascript:(.*)[\\\"\\']", "\"\"");
        return str;
    }

    public static String bigDecimalToString(BigDecimal dec) {
        String str = "";
        if (dec != null) {
            str = dec.toString();
        }
        return str;
    }

    /**
     * 替换所有空格
     *
     * @param pwd
     * @return
     */
    public static String removeTrim(String pwd) {
        if (pwd == null || "".equals(pwd.trim())) {
            return "";
        }
        //替换所有空白字符
        return pwd.replace((char) 12288, ' ').replaceAll("\\s+", "");
    }

    /**
     * 替换所有空格及符号
     *
     * @param pwd
     * @return
     */
    public static String removeTrimAndPunct(String pwd) {
        if (pwd == null || "".equals(pwd.trim())) {
            return "";
        }
        //替换所有空白字符
        return pwd.replace((char) 12288, ' ').replaceAll("\\s+", "").replaceAll("[\\p{Punct}\\pP]+", "");
    }

    /**
     * 替换所有空格及符号 excel的空格为160
     *
     * @param pwd
     * @return
     */
    public static String removeTrimExcel(String pwd) {
        if (pwd == null || "".equals(pwd.trim())) {
            return "";
        }
        //替换所有空白字符
        return pwd.replace((char) 160, ' ');
    }

    public static String removeSign(String s) {
        char[] chars = s.toCharArray();
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < chars.length; i++) {
            if ((chars[i] >= 19968 && chars[i] <= 40869) || (chars[i] >= 97 && chars[i] <= 122) || (chars[i] >= 65 && chars[i] <= 90)) {
                buffer.append(chars[i]);
            }
        }
        System.out.print("buffer=" + buffer);
        return buffer.toString();
    }

    /**
     * 校验出版日期
     *
     * @param proPubData
     * @return
     */
    public static boolean checkDateFormat(String proPubData) {
        String proPubDate = "^[0-9]{4}(0?[1-9]|1[0-2])$";
        if (!Strings.isNullOrEmpty(proPubData)) {
            return proPubData.matches(proPubDate);
        } else {
            return true;
        }
    }

    /**
     * 空转
     *
     * @param obj
     * @return
     */
    public static String Null2String(Object obj) {
        if (obj == null) {
            if (obj instanceof Double) {
                return "0";
            } else if (obj instanceof Float) {
                return "0";
            } else if (obj instanceof Integer) {
                return "0";
            } else {
                return "";
            }
        }
        return obj.toString();
    }

    public static String getStringLength(String str) {
        String size = "";
        long fileS = str.length();
        DecimalFormat df = new DecimalFormat("#.00");
        if (fileS < 1024) {
            size = df.format((double) fileS) + "BT";
        } else if (fileS < 1048576) {
            size = df.format((double) fileS / 1024) + "KB";
        } else if (fileS < 1073741824) {
            size = df.format((double) fileS / 1048576) + "MB";
        } else {
            size = df.format((double) fileS / 1073741824) + "GB";
        }
        return size;
    }

    public static void main(String[] args) {
        String dateStr = "2022-05-20 10:46:41";
        String dateFormat = dateFormat(dateStr);
        System.out.println(dateFormat);
    }

    private static String dateFormat(String str) {
        StringBuffer sb;
        if (str.length() == 14) {
            sb = new StringBuffer(str.substring(0, 4));
            sb.append("-").append(str, 4, 6);
            sb.append("-").append(str, 6, 8);
            sb.append(" ").append(str, 8, 10);
            sb.append(":").append(str, 10, 12);
            sb.append(":").append(str, 12, 14);
            return sb.toString();
        }
        return null;
    }




}